package com.example.newdemo.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Context;


import com.example.newdemo.utils.permiss.Permission;
import com.example.newdemo.utils.permiss.RxPermissions;

import io.reactivex.functions.Consumer;

public class PermissionUtils {

    public static void getPermission(Activity context){
        RxPermissions rxPermissions = new RxPermissions(context);

        rxPermissions.request(Manifest.permission.CAMERA,
                Manifest.permission.RECORD_AUDIO)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        if (aBoolean){
                            // 获取全部权限成功
                        }else{
                            // 获取全部权限失败
                        }
                    }
                });

    }

    public static void getMultsPermiss(Activity context){
        RxPermissions rxPermissions = new RxPermissions(context);
        rxPermissions.requestEach(Manifest.permission.CAMERA,
                Manifest.permission.RECORD_AUDIO)
                .subscribe(new Consumer<Permission>() {
                    @Override
                    public void accept(Permission permission) throws Exception {
                        if (permission.name == Manifest.permission.CAMERA){
                            if (permission.granted){
                                // 获取相机权限成功
                            }else{
                                // 获取相机权限失败
                            }
                        }else if (permission.name == Manifest.permission.RECORD_AUDIO){
                            if (permission.granted){
                                // 获取录音权限成功
                            }else{
                                // 获取录音权限失败
                            }
                        }
                    }
                });
    }



}
